#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define rep(i, s, t) for (int i = s; i <= t; ++i)
#define per(i, s, t) for (int i = t; i >= s; --i)

const int N = 105;

int n, q, p;
int a[N], b[N];
int f[N][N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	cout << fixed << setprecision(15); 
	cerr << fixed << setprecision(15);
	
	freopen("string.in", "r", stdin);
	freopen("string.out", "w", stdout);
	
	cin >> n >> q >> p;
	rep(i, 1, n) cin >> a[i];
	rep(x, 0, p-1) rep(y, 0, p-1) {
		rep(i, 1, n) b[i] = (1ll * x * a[i] + y) % p;
		rep(i, 1, n) rep(j, i, n) {
			bool ok = 1;
			rep(k, i, j) if(b[k] != a[j-(k-i)]) {
				ok = 0;
				break;
			}
			if(ok) ++f[x][y];
		}
	}
	while(q--) {
		int op, x; cin >> op >> x;
		int ans = 0;
		if(op == 1) {
			rep(i, 0, p-1) ans += f[x][i];
		} else {
			rep(i, 0, p-1) ans += f[i][x];
		}
		cout << ans << "\n";
	}
	
	return 0;
}
